<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="currentTab">
      <el-tab-pane name="accout">
        <template #label>
          <span class="custom-tabs-label">
            <!--<el-icon><calendar /></el-icon>-->
            <span>账号登录</span>
          </span>
        </template>
        <login-accout ref="accoutRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <!--<el-icon><calendar /></el-icon>-->
            <span>手机登录</span>
          </span>
        </template>
        <login-phone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>

    <div class="accout-control">
      <el-checkbox v-model="isKeepPassowrd">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="handleLoginClick"
      >立即登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

import loginAccout from './login-accout.vue'
import loginPhone from './login-phone.vue'

export default defineComponent({
  components: { loginAccout, loginPhone },
  setup() {
    //定义属性
    const isKeepPassowrd = ref(true)
    const accoutRef = ref<InstanceType<typeof loginAccout>>()
    const phoneRef = ref<InstanceType<typeof loginPhone>>()
    const currentTab = ref<string>('accout')

    //定义方法
    const handleLoginClick = () => {
      if (currentTab.value === 'accout') {
        accoutRef.value?.loginAction(isKeepPassowrd.value)
      } else {
        //phoneRef.value?.loginAction(isKeepPassowrd.value)
      }
    }

    return {
      isKeepPassowrd,
      handleLoginClick,
      accoutRef,
      phoneRef,
      currentTab
    }
  }
})
</script>

<style scoped lang="less">
.login-panel {
  width: 320px;
  .title {
    text-align: center;
  }

  .accout-control {
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin: 10px 0;
  }
}
</style>
